<template>
	<view class="feedBack">
		<view class="descBox">
			<view class="title">
				问题描述
			</view>
			<textarea class="textareaitem" v-model="text" value="" placeholder="" placeholder="请输入" />
		</view>

		<view class="imgBox">
			<view class="title">
				上传图片
			</view>

			<view class="imgContent">
				<view class="imginner" v-for="(item,index) in imgs ">
					<image :src="item" style="width: 140rpx;height: 140rpx;border-radius: 20rpx;" mode=""></image>
					<view class="delIcon">
						<u-icon name="close-circle" size="18" @click="handleDel(index)"></u-icon>
					</view>
				</view>
				<image :src="imaurl+'upload.png'" style="width: 140rpx;height: 140rpx;" mode="" @click="handleUpload">
				</image>
			</view>
		</view>

		<view class="btns" @click="handleSubmit">
			确认提交
		</view>

	</view>
</template>

<script>
	import {
		submituserfeed,
		uploadImg
	} from "@/api/api.js"
	export default {
		data() {
			return {
				text: "",
				imgs: [],
				imaurl: "https://szgb.tongchengbang.cc/img/image/"
			}
		},
		onLoad() {

		},
		methods: {

			handleUpload() {
				let that = this
				uni.chooseImage({
					count: 9, //默认9
					sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album', 'camera'], //从相册选择
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						console.log("tempFilePaths", tempFilePaths)
						for (let i = 0; i < tempFilePaths.length; i++) {
							uni.uploadFile({
								url: uploadImg, //仅为示例，非真实的接口地址
								filePath: tempFilePaths[i],
								name: 'file',
								// formData: {
								// 	'user': 'test'
								// },
								success: (uploadFileRes) => {
									console.log("图片路径//////", JSON.parse(uploadFileRes.data).data);
									if (that.imgs.length >= 9) {
										uni.showToast({
											title: '最多可上传9张图片！',
											duration: 1000,
											icon: "none",
										});
									} else {
										that.imgs.push(JSON.parse(uploadFileRes.data).data.url)
									}
								},
								fail(e) {
									console.log("上传图片", e)
								}
							});
						}
					}
				});
			},
			handleDel(index) {
				this.imgs.splice(index, 1)

			},

			async handleSubmit() {
				if (this.text == '') {
					uni.showToast({
						title: '请输入反馈内容！',
						duration: 1500,
						icon: "none",
					});
					return
				}
				let data = {
					text: this.text,
					imgs: this.imgs.join(',')
				}
				let res = await submituserfeed(data)
				if (res.code == 1) {
					uni.showToast({
						title: res.msg,
						duration: 1500,
						icon: "none",
					});
					setTimeout(() => {
						uni.navigateBack({
							delta: 1
						})
					}, 2000)
				} else {
					uni.showToast({
						title: res.msg,
						duration: 1500,
						icon: "none",
					});
				}
			},

		}
	}
</script>

<style scoped lang="scss">
	.title {
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		font-size: 32rpx;
		color: #333333;
		line-height: 38rpx;
	}

	.descBox {
		width: 100%;
		height: 324rpx;
		background: #FFFFFF;
		padding: 30rpx 40rpx;
		box-sizing: border-box;

		.textareaitem {
			width: 670rpx;
			height: 200rpx;
			background: #F6F6F6;
			border-radius: 20rpx 20rpx 20rpx 20rpx;
			margin-top: 20rpx;
			padding: 30rpx;
			box-sizing: border-box;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 28rpx;
			line-height: 33rpx;
		}
	}

	.imgBox {
		width: 750rpx;
		// height: 262rpx;
		background: #FFFFFF;
		padding: 30rpx 40rpx;
		box-sizing: border-box;
		margin-top: 20rpx;

		.imgContent {
			margin-top: 20rpx;
			display: flex;
			flex-wrap: wrap;

			.imginner {
				width: 140rpx;
				height: 140rpx;
				margin-right: 20rpx;
				margin-bottom: 20rpx;
				position: relative;

				.delIcon {
					position: absolute;
					top: -10rpx;
					right: -10rpx;
				}
			}
		}
	}

	.btns {
		width: 630rpx;
		height: 88rpx;
		background: #00BF52;
		border-radius: 200rpx 200rpx 200rpx 200rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 38rpx;
		color: #FFFFFF;
		line-height: 88rpx;
		text-align: center;
		margin: 0 auto;
		position: absolute;
		bottom: 200rpx;
		left: 50%;
		margin-left: -315rpx;
	}
</style>